home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / s0ftpj / rpcprogs.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-12-17  |  2.6 KB  |  133 lines

  1. /* RPC PROGRAM SCANNER
  2.  
  3.    This scanner can find an rpc program thx to its program numbers.
  4.  
  5.    If u r looking for a prog number type:
  6.  
  7.    cat /etc/rpc ;)
  8.  
  9.    pIGpEN/S0ftPj'99
  10. */  
  11.  
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <netdb.h>
  16. #include <signal.h>
  17. #include <sys/socket.h>
  18. #include <netinet/in.h>
  19. #include <arpa/inet.h>
  20. #include <netinet/ip.h>
  21. #include <rpc/rpc.h>
  22. #include <rpc/pmap_prot.h>
  23. #include <rpc/pmap_clnt.h>
  24.  
  25.  
  26. int check(char *host);
  27. unsigned long int res(char *p);
  28. void woopy(int s);
  29. void usage(char *s);
  30. void scan(char *i, char *o);
  31.  
  32. int RNUMBER;
  33.  
  34. void usage(char *s)
  35. {
  36.   printf("Usage: %s <inputfile> <outputfile> <rpcnumber>\n\n\n\n",s);
  37.   exit(-1);
  38. }
  39.  
  40. void main(int argc, char **argv)
  41. {
  42.   system("clear");
  43.   printf("RPC PROGRAM NUMBER FiNDER\n");
  44.   printf("-=-=-=-=-=-=-=-=-=-=-=-=-\n");
  45.   printf("Coded by pIGpEN/S0ftPj99\n");
  46.   printf("Original scanner coded by BiT'97\n\n\n");
  47.   
  48.   if(argc<4)
  49.     usage(argv[0]);
  50.   RNUMBER=atoi(argv[3]);
  51.   scan(argv[1],argv[2]);
  52. }
  53.  
  54. void scan(char *i, char *o)
  55. {
  56.   FILE *iff, *of;
  57.   char buf[512];
  58.  
  59.   if((iff=fopen(i,"r")) == NULL)
  60.     return;
  61.   while(fgets(buf,512,iff) != NULL)
  62.   {
  63.     if(buf[strlen(buf)-1]=='\n')
  64.       buf[strlen(buf)-1]=0;
  65.     if(check(buf) && (of=fopen(o,"a")) != NULL) {
  66.       buf[strlen(buf)+1]=0;
  67.       buf[strlen(buf)]='\n';
  68.  
  69.       fputs(buf,of);
  70.       fclose(of);
  71.     }
  72.   }
  73.   fclose(iff);
  74. }
  75.  
  76. void woopy(int s)
  77. {
  78.   return;
  79. }
  80.  
  81. int check(char *host)
  82. {
  83.   struct sockaddr_in server_addr;
  84.   struct pmaplist *head = NULL;
  85.   int sockett = RPC_ANYSOCK;
  86.   struct timeval minutetimeout;
  87.   register CLIENT *client;
  88.   struct rpcent *rpc;
  89.  
  90.   server_addr.sin_addr.s_addr=res(host);
  91.   server_addr.sin_family=AF_INET;
  92.   server_addr.sin_port = htons(PMAPPORT);
  93.   minutetimeout.tv_sec = 15;
  94.   minutetimeout.tv_usec = 0;
  95.  
  96.   /* cause clnttcp_create uses connect() */
  97.   signal(SIGALRM,woopy);
  98.   alarm(15);
  99.  
  100.   if ((client = clnttcp_create(&server_addr, PMAPPROG,
  101.         PMAPVERS, &sockett, 50, 500)) == NULL) {
  102.     alarm(0);
  103.     signal(SIGALRM,SIG_DFL);
  104.     return 0;
  105.   }
  106.   alarm(0);
  107.   signal(SIGALRM,SIG_DFL);
  108.  
  109.   if (clnt_call(client, PMAPPROC_DUMP, (xdrproc_t) xdr_void, NULL,
  110.         (xdrproc_t) xdr_pmaplist, &head, minutetimeout) != RPC_SUCCESS)
  111.     return 0;
  112.   if (head != NULL)
  113.     for (; head != NULL; head = head->pml_next)
  114.       if((rpc = getrpcbynumber(head->pml_map.pm_prog)))
  115.         if((rpc->r_number)==RNUMBER){
  116.           printf("Rpc Number Found At: %s\n",host); 
  117.           return 1;}
  118.   return 0;
  119. }
  120.  
  121. unsigned long int res(char *p)
  122. {
  123.    struct hostent *h;
  124.    unsigned long int rv;
  125.  
  126.    h=gethostbyname(p);
  127.    if(h!=NULL)
  128.      memcpy(&rv,h->h_addr,h->h_length);
  129.    else
  130.      rv=inet_addr(p);
  131.    return rv;
  132. }
  133.